
<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form divClass" v-if="headerShow">
        <div>
          <a-form size="small" :model="pageData" layout="inline">
            <a-form-item label="项目">
              <!-- <a-select popup-container="html"  class="bacClass" :loading="loading" :allowClear="true" @search="handleSearch"
                            v-model="pageData.dropDownData" :filter-option="false" allow-search @focus="focusSel">
                            <a-option v-for="item in pageData.clothList" :value="item['classify']">{{
                                item['classify']
                            }}</a-option>
                                    </a-select> -->
              <a-input allow-clear :style="{ width: '200px' }" class="bacClass" placeholder=""
                v-model="pageData.dropDownData" @press-enter="huiche" />
            </a-form-item>
          </a-form>
        </div>
        <div class="my-tool-bar">
          <Toolbar style="float: right" :items="['查询', '新增', '删除']" @add="addHandler" @import="importHandler"
            @del="deleteHandler" @select="selectHandler" @export="exports" @excel="downloadHandler">
          </Toolbar>
        </div>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up v-if="headerShow" @click="headerShow = false" :strokeWidth="2" :size="18" />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
    </template>
    <template #pageTabel>
      <!-- 主表 -->
      <!-- <a-tabs   :justify="true">
                            <a-tab-pane> -->
      <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple"
        @grid-ready="gridReady" style="height: 100%" :defaultColDef="defaultColDef" class="ag-theme-alpine"
        :rowData="table.dataList" :columnDefs="tc" :localeText="localeText1"></AgGridVuesCopys>
      <!-- </a-tab-pane>
                        </a-tabs> -->
    </template>
    <paginationCopys :page-size-options="pagingList1" :total="total" show-total show-jumper show-page-size @change="PageSize"
      @page-size-change="change1" style="justify-content: center" :page-size="pagination.pageSize"
      :current="pagination.page" />
    <!-- 主表抽屉 -->
    <a-drawer :drawer-style="{ zIndex: 9999 }" :mask-closable="false" :width="400" :visible="pageData.showAdd"
      unmountOnClose @ok="sideOk" @cancel="pageData.showAdd = false" cancel-text="关闭" ok-text="保存"
      :ok-loading="pageData.pageLoading">
      <template #title>
        {{ pageData.sideTitle }}
      </template>
      <div>
        <a-form ref="formRef" layout="horizontal" :model="dataForm">
          <a-form-item label-col-flex="80px" label="项目" field="classify" :validate-trigger="['change', 'blur']"
            :rules="[{ required: true, message: '项目必填' }]">
            <a-input class="bacClass" placeholder=" " v-model="dataForm.classify" />
          </a-form-item>
          <a-form-item label-col-flex="80px" label="要求分类" field="classify" :validate-trigger="['change', 'blur']"
            :rules="[{ required: true, message: '要求分类必填' }]">
            <!-- <a-input class="bacClass" placeholder=" " v-model="dataForm.requireClassify" />
                         -->
            <a-select popup-container="html"  class="bacClass" :style="{ width: '400px' }" :loading="loading" @search="handleSearch1"
              v-model="dataForm.requireClassify" :filter-option="false" allow-search allow-clear @focus="focusSel1">
              <a-option v-for="item in pageData.nameList" :value="item['requireClassify']">{{ item['requireClassify']
              }}</a-option>
            </a-select>
          </a-form-item>
          <a-form-item label-col-flex="80px" label="备注">
            <a-textarea class="bacClass" v-model="dataForm.remark" :max-length="400" allow-clear show-word-limit />
          </a-form-item>
        </a-form>
      </div>
    </a-drawer>
    <!-- 子表抽屉 -->
    <a-drawer :drawer-style="{ zIndex: 9999 }" :mask-closable="false" :width="400" :visible="pageData.showAdd1"
      unmountOnClose @ok="sideOk1" @cancel="pageData.showAdd1 = false" cancel-text="关闭" ok-text="保存">
      <template #title>
        {{ pageData.sideTitle1 }}
      </template>
      <div>
        <a-form ref="formRef" layout="horizontal" :model="dataForm">
          <a-form-item label="选项" field="optionx" :validate-trigger="['change', 'blur']"
            :rules="[{ required: true, message: '选项必填' }]">
            <a-input placeholder=" " v-model="dataForm.optionx" />
          </a-form-item>
          <a-form-item label="单位" field="units" :validate-trigger="['change', 'blur']"
            :rules="[{ required: true, message: '单位必填' }]">
            <a-input placeholder=" " v-model="dataForm.units" />
          </a-form-item>
          <a-form-item label-col-flex="80px" label="备注">
            <a-textarea class="bacClass" v-model="dataForm.remark" :max-length="400" allow-clear show-word-limit />
          </a-form-item>
        </a-form>
      </div>
    </a-drawer>
    <!-- 子表 -->
    <a-drawer ok-text="关闭" :hide-cancel="true" :drawer-style="{ zIndex: 999 }" :mask-closable="false" :width="400"
      popup-container=".main-base-style" height="90vh" :visible="pageData2.showAdd" placement="bottom" unmount-on-close
      @ok="sideNo1" :closable="false" @cancel="pageData2.showAdd = false" :ok-loading="pageData.pageLoading1">
      <template #title> 默认值设定 </template>

      <div class="my-tool-bar">
        <Toolbar :items="['新增', '删除']" @add="addHandler1" @import="importHandler" @del="deleteHandler1"
          @select="selectHandler" @export="exports" @excel="downloadHandler">
        </Toolbar>
      </div>
      <!-- <a-tabs   :justify="true">
        <a-tab-pane> -->
      <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple"
        @grid-ready="gridReady1" style="height: 100%" :defaultColDef1="defaultColDef1" class="ag-theme-alpine"
        :rowData="dataList1" :columnDefs="dc" :localeText="localeText1"></AgGridVuesCopys>
      <!-- </a-tab-pane>
      </a-tabs> -->
    </a-drawer>
  </pageTabelLayout>
</template>

<script lang="ts">
import { post, get } from '@/api/http'
import { useTable, useRowKey, useTableColumn, usePagination, useRowSelection } from '@/hooks/table'
import { localeText } from '@/api/aggridZw'
import { ref, reactive, onMounted, onActivated, onUnmounted } from 'vue'
import Toolbar from '@/components/Toolbar.vue'
import { Form, Message, Modal, Pagination } from '@arco-design/web-vue'
import { FormInstance } from '@arco-design/web-vue/es/form'
import emitter from '@/hooks/useEventBus'
import validate from '@/hooks/useValidate'
import { baseURL } from '../../../api/axios.config'
import axios from 'axios'
import filedownload from 'js-file-download'

import PageTabelLayout from '@/components/pageTabelLayout.vue'
import checkBoxRender from '@/components/aggridCellRenDerer/checkBoxRender.vue'
import { pagingList } from "@/api/paging";
interface ClothSet {
  id: any
  serialNumber: number | undefined
  classify: string | undefined
  deleteState: any
  remark: string | undefined
  createName: string | undefined
  createTime: string | undefined
  updateName: string | undefined
  updateTime: string | undefined
  requireClassify: any
  optionx: any
  defaultx: any
  units: any
  requireClassifyID: any
}

export default {
  name: 'CustomerRequirements',
  setup() {
    const headerShow = ref<boolean>(true)
    //查询
    const scrollbar = ref(true)

    function doRefresh() {
      post({
        url: 'pdm/RequireClassify/getPage',
        data: {
          page: pagination.page,
          size: pagination.pageSize,
          deleteState: 0,
          classify: pageData.dropDownData,
        },
      })
        .then(({ data, code }: any) => {
          if (code === 200) {
            table.handleSuccess(data.list)
            gridOption.value.setRowData(data.list)
            total.value = data.total
          }
        })
        .catch(console.log)
        .finally(() => {
          pageData.pageLoading = false
        })
    }

    const { selectedRowKeys, onSelectionChange } = useRowSelection()
    const pagination = usePagination(doRefresh)
    const table = useTable()
    const rowKey = useRowKey('id')
    //检验表单是否含有中文的方法
    const hasChiese = validate.includeChinese
    const tableColumns = useTableColumn([
      {
        title: '序号',
        key: 'serialNumber',
        dataIndex: 'serialNumber',
        width: 150,
      },
      {
        title: '项目',
        key: 'classify',
        dataIndex: 'classify',
        width: 150,
      },
      {
        title: '要求分类',
        key: 'requireClassify',
        dataIndex: 'requireClassify',
        width: 150,
      },
      {
        title: '备注',
        key: 'remark',
        dataIndex: 'remark',
        width: 150,
      },
      {
        title: '默认值信息',
        key: 'id',
        dataIndex: 'id',
        width: 150,
        slotName: 'act1',
        fixed: 'right',
      },
      {
        title: '创建人',
        key: 'createName',
        dataIndex: 'createName',
        width: 150,
      },
      {
        title: '创建时间',
        key: 'createTime',
        dataIndex: 'createTime',
        width: 150,
      },
      {
        title: '最后修改人',
        key: 'updateName',
        dataIndex: 'updateName',
        width: 150,
      },
      {
        title: '最后修改时间',
        key: 'updateTime',
        dataIndex: 'updateTime',
        width: 150,
      },

      {
        title: '操作',
        key: 'id',
        dataIndex: 'id',
        slotName: 'act',
        width: 150,
        fixed: 'right',
      },
    ])
    const tableColumns1 = useTableColumn([
      {
        title: '序号',
        key: 'requireClassifyID',
        dataIndex: 'requireClassifyID',
        width: 250,
      },
      {
        title: '项目',
        key: 'classify',
        dataIndex: 'classify',
        width: 250,
      },
      {
        title: '选项',
        key: 'optionx',
        dataIndex: 'optionx',
        width: 250,
      },
      {
        title: '单位',
        key: 'units',
        dataIndex: 'units',
        width: 250,
      },
      {
        title: '默认状态',
        key: 'defaultx',
        dataIndex: 'defaultx',
        slotName: 'act3',
        width: 150,
        fixed: 'right',
      },
      {
        title: '备注',
        key: 'remark',
        dataIndex: 'remark',
        width: 150,
      },
      {
        title: '创建人',
        key: 'createName',
        dataIndex: 'createName',
        width: 150,
      },
      {
        title: '创建时间',
        key: 'createTime',
        dataIndex: 'createTime',
        width: 150,
      },
      {
        title: '操作',
        key: 'id',
        dataIndex: 'id',
        slotName: 'act4',
        width: 300,
        fixed: 'right',
      },
    ])
    const scroll = {
      x: 2000,
      y: 200,
    }
    const tablediv = ref(null)
    const pageData = reactive<{
      clothList: ClothSet[]
      showAdd: boolean
      showAdd1: boolean
      sideTitle: string
      sideTitle1: string
      dropDownData: any
      pageLoading: boolean
      pageLoading1: boolean
      theight: number
      tablediv: any
      rHeight: number | undefined
      nameList: []
    }>({
      clothList: [],
      sideTitle1: '新增默认值',
      showAdd: false,
      showAdd1: false,
      sideTitle: '新增项目分类',
      dropDownData: '',
      pageLoading: false,
      pageLoading1: false,
      theight: 0,
      tablediv: null,
      rHeight: 0,
      nameList: [],
    })
    //下拉框得到焦点
    const focusSel = () => {
      selCxAll({ classify: '' })
    }
    //下拉数据
    const options = ref<any>(pageData.clothList)
    const loading = ref(false)
    const handleSearch = (value: any) => {
      if (value) {
        const ob = { classify: value }
        loading.value = true
        selCxAll(ob)
        options.value = pageData.clothList
        loading.value = false
      } else {
        options.value = []
      }
    }

    //下拉框查询
    function selCxAll(val: any) {
      post({
        url: 'pdm/RequireClassify/getFieldValue',
        data: val,
      }).then(({ data, code }: any) => {
        if (code === 200) {
          pageData.clothList = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    onMounted(() => {
      // 第一个页面需要在刚进入就调用一次  切换tap时也需要调用
      doRefresh()
      // selCxAll({});
      // 切换tap到本页面执行的方法
      emitter.on('CustomerRequirements', () => {
        // selCxAll({});
        doRefresh()
      })
      pageData2.rHeight = document.getElementsByClassName('main-section')[0]?.clientHeight
      //弹出层的高
      if (pageData2.rHeight !== undefined) {
        pageData2.rHeight = pageData2.rHeight - 100
      }
    })
    let cxbl = ''
    //查询
    const selectHandler = () => {
      pagination.page = 1
      // cxbl = pageData.dropDownData
      if (pageData.dropDownData !== '') {
        doRefresh()
      } else {
        doRefresh()
      }
    }
    const queryData = reactive({
      clothType: '',
    })
    const addHandler = () => {
      for (var key in dataForm) {
        if (key === 'id') {
          dataForm[key] = null
        } else {
          dataForm[key] = ''
        }
      }
      pageData.showAdd = true
      pageData.sideTitle = '新增项目分类'
    }
    const addHandler1 = () => {
      for (var key in dataForm) {
        if (key === 'id') {
          dataForm[key] = null
        } else {
          dataForm[key] = ''
        }
      }
      pageData.showAdd1 = true
      pageData.sideTitle1 = '新增默认值'
    }
    const dataForm = reactive<ClothSet>({
      id: null,
      serialNumber: 0,
      createTime: '',
      classify: '',
      remark: '',
      updateTime: '',
      updateName: '',
      createName: '',
      deleteState: 0,
      requireClassify: '',
      optionx: '',
      defaultx: '',
      units: '',
      requireClassifyID: '',
    })

    // 新增
    const formRef = ref<FormInstance>()
    const sideOk = () => {
      formRef.value?.validate().then((err) => {
        if (!err) {
          pageData.pageLoading = true
          if (pageData.sideTitle === '新增项目分类') {
            post({
              url: 'pdm/RequireClassify/insert',
              data: [dataForm],
            }).then((res: any) => {
              if (res.code === 200) {
                formRef.value?.resetFields()
                pageData.showAdd = false
                pageData.pageLoading = false
                Message.success({
                  content: '新增成功',
                  duration: 5000,
                })
                doRefresh()
              } else {
                Message.error({
                  content: res.message,
                  duration: 5000,
                })
              }
            }).finally(() => {
              doRefresh();
              pageData.pageLoading = false
            })

          } else {
            post({
              url: 'pdm/RequireClassify/updateList',
              data: dataForm,
            }).then((res: any) => {
              if (res.code === 200) {
                formRef.value?.resetFields()
                pageData.showAdd = false
                pageData.pageLoading = false
                Message.success({
                  content: '修改成功',
                  duration: 5000,
                })
                doRefresh()
              } else {
                Message.error({
                  content: res.message,
                  duration: 5000,
                })
              }
            }).finally(() => {
              doRefresh();
              pageData.pageLoading = false
            })

          }
        }
      })
    }
    const sideOk1 = () => {
      formRef.value?.validate().then((err) => {
        if (!err) {
          // pageData.pageLoading1 = true
          if (pageData.sideTitle1 === '新增默认值') {
            post({
              url: 'pdm/RequireClassifySon/insert',
              data: [
                {
                  classify: keyList.shelveName,
                  requireClassifyID: keyList.shelveId,
                  optionx: dataForm.optionx,
                  units: dataForm.units,
                  remark: dataForm.remark,
                },
              ],
            }).then((res: any) => {
              if (res.code === 200) {
                formRef.value?.resetFields()
                pageData.showAdd1 = false
                // pageData.pageLoading = false
                Message.success({
                  content: '新增成功',
                  duration: 5000,
                })
                doRefresh1()
              } else {
                Message.error({
                  content: res.message,
                  duration: 5000,
                })
              }
            })
          } else {
            post({
              url: 'pdm/RequireClassifySon/update',
              data: [dataForm],
            }).then((res: any) => {
              if (res.code === 200) {
                formRef.value?.resetFields()
                pageData.showAdd1 = false
                // pageData.pageLoading = false
                Message.success({
                  content: '修改成功',
                  duration: 5000,
                })
                doRefresh1()
              } else {
                Message.error({
                  content: res.message,
                  duration: 5000,
                })
              }
            })
          }
        }
      })
    }
    const deleteHandler = () => {
      if (gridOption.value.getSelectedRows().length === 0) {
        Message.error('请先勾选')
        return
      }
      Modal.confirm({
        title: '系统提示',
        content: '确认删除选中的数据?',
        onOk() {
          post({
            url: 'pdm/RequireClassify/delete',
            data: gridOption.value.getSelectedRows().map((o: any) => {
              return o.id
            }),
          }).then(({ code, data, message }: any) => {
            if (code === 200) {
              Message.success({
                content: '删除成功',
                duration: 5000,
              })

              pagination.page = 1
              doRefresh()
            } else {
              Message.error({
                content: '删除失败',
                duration: 5000,
              })
            }
          })
        },
      })
    }
    const deleteHandler1 = () => {
      if (gridOption1.value.getSelectedRows().length === 0) {
        Message.error('请先勾选')
        return
      }
      Modal.confirm({
        title: '系统提示',
        content: '确认删除选中的数据?',
        onOk() {
          post({
            url: 'pdm/RequireClassifySon/delete',
            data: gridOption1.value.getSelectedRows().map((o: any) => {
              return o.id
            }),
          }).then(({ code, data, message }: any) => {
            if (code === 200) {
              Message.success({
                content: '删除成功',
                duration: 5000,
              })

              pagination.page = 1
              doRefresh1()
            } else {
              Message.error({
                content: '删除失败',
                duration: 5000,
              })
            }
          })
        },
      })
    }
    const editHandler = (record: ClothSet) => {
      for (var key in record) {
        dataForm[key] = record[key]
      }
      pageData.sideTitle = '修改项目分类'
      pageData.showAdd = true
    }
    const editHandler2 = (record: ClothSet) => {
      for (var key in record) {
        dataForm[key] = record[key]
      }
      pageData.sideTitle1 = '修改默认值'
      pageData.showAdd1 = true
    }

    //导出
    const exports = () => {
      if (selectedRowKeys.value.length === 0) {
        Message.error('请先勾选')
        return
      } else {
        //将表头拼接出来
        let head =
          '<th>编号</th><th>名称</th><th>备注</th><th>创建人</th><th>创建时间</th><th>最后修改人</th><th>最后修改时间</th>'
        //拿到当前表格数据与勾选的行做筛选

        let nowRow = table.dataList.filter(function (o) {
          return selectedRowKeys.value.indexOf(o['id']) !== -1
        })
        let body = ''
        nowRow.forEach(function (o) {
          body += '<tr><td>' + o['merceryCode'] + '</td>'
          body += '<td>' + o['merceryName'] + '</td>'
          body += '<td>' + o['remark'] + '</td>'
          body += '<td>' + o['createName'] + '</td>'
          body += '<td>' + o['createTime'] + '</td>'
          body += '<td>' + o['updateName'] + '</td>'
          body += '<td>' + o['updateTime'] + '</td>'
          body += '</tr>'
        })
        tableToXlsx(head, '布类资料', body)
        console.log(table)
      }
    }

    function tableToXlsx(head: any, filename: any, body: any) {
      const uri = 'data:application/vnd.ms-excel;base64,',
        template = `<html>
            <head><meta charset="UTF-8"></head>
            <body><table border="1"><tr>${head}</tr>${body}</table></body>
        </html>`

      const a = document.createElement('a')
      a.href = uri + window.btoa(unescape(encodeURIComponent(template)))
      a.download = filename
      a.click()
      document.removeChild(a)
    }

    //模板下载
    const downloadHandler = () => {
      axios
        .get(baseURL + '/product/mercery/uploadMerceryModel', {
          responseType: 'blob',
          headers: {
            token: sessionStorage.getItem('USER-TOKEN-KEY'),
          },
        })
        .then((res) => {
          if (res.status === 200) {
            filedownload(res.data, '布类资料.xlsx')
          }
        })
    }
    //导入
    const importHandler = () => {
      const inputEle: HTMLInputElement = document.createElement('input')
      inputEle.type = 'file'
      inputEle.id = 'fileUploadExcel'
      inputEle.accept =
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel'
      inputEle.addEventListener('change', (e) => {
        const formData = new FormData()
        if (inputEle.files !== null) {
          formData.append('file', inputEle.files[0] || '')
        } else {
          Message.warning('未选择文件！')
          return
        }
        pageData.pageLoading = true
        axios
          .post(baseURL + '/product/mercery/analyseMerceryModel', formData, {
            headers: {
              'Content-Type': 'multipart/form-data',
              token: sessionStorage.getItem('USER-TOKEN-KEY'),
            },
          })
          .then((result) => {
            if (result.data['code'] === 200) {
              Message.success('导入成功')
            } else {
              Message.error(result.data.message)
            }
          })
          .finally(() => {
            pageData.pageLoading = false
            doRefresh()
          })
      })
      inputEle.click()
    }
    const pageData2 = reactive<{
      showAdd: boolean
      rHeight: any
    }>({
      showAdd: false,
      rHeight: 0,
    })
    interface keyscwType {
      firm: any
      warehouseId: any
      warehouseName: any
      id: any
      name: any
      shelveName: any
    }
    let keyscw: keyscwType = {
      firm: '',
      warehouseId: '',
      warehouseName: '',
      id: '',
      name: '',
      shelveName: '',
    }
    // 定义从主表获取过来的数据
    let keyList = {
      shelveId: 0,
      shelveName: '',
      sheID: '',
    }
    // 子表查询渲染
    function doRefresh1() {
      pageData.pageLoading = true

      post({
        url: 'pdm/RequireClassify/getListId',
        data: {
          // requireClassifyID: keyList.shelveId,
          id: keyList.shelveId,
          //   classify: keyList.shelveName,
          // deleteState:0,
        },
      })
        .then(({ data, code }: any) => {
          if (code === 200) {
            table.handleSuccess(data.list)
            // gridOption1.value.setRowData(data.list)
            dataList1.value = data.list
            total.value = data.total
          }
        })
        .catch(console.log)
        .finally(() => {
          pageData.pageLoading = false
        })
    }
    // 点击按钮获取主表数据
    const editHandler1 = (key: any) => {
      keyList.shelveId = Number(key.id)
      keyList.shelveName = key.classify
      // keyList.sheID = dataForm.defaultx
      // opCwdata(keyList)
      // keyscw = key
      pageData2.showAdd = true
      doRefresh1()
      console.log(checkeded)
    }
    const editHandler3 = (key: any) => {
      keyscw = key
      open1(key)
      doRefresh1()
    }

    function open1(key: any) {
      console.log(key)

      post({
        url: 'pdm/RequireClassifySon/updateDefaultx',
        data: [
          {
            id: key.id,
            requireClassifyID: key.requireClassifyID,
            defaultx: key.defaultx,
          },
        ],
      }).then(({ data, code }: any) => {
        if (code === 200) {

        }
      })
        .catch(console.log).finally(() => {
          pageData.pageLoading = false
          doRefresh1()
        })
    }
    let lengsDs: number = 0
    // 表格准备事件
    const gridOption = ref()
    const gridReady = (params: any) => {
      gridOption.value = params.api
    }
    const defaultColDef = {
      sortable: true,
      resizable: true,
      filter: true,
      // flex: 1
    }
    let tc: any[] = tableColumns.map((o) => {
      let obj = {
        headerName: o.title,
        field: o.key,
        pinned: o['fixed'],
      }
      if (o.slotName === 'act') {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['lockPosition'] = 'right'
        obj['width'] = 80
        obj['cellRenderer'] = {
          template: `<el-button style="color:#165dff;" link @click="a">修改</el-button>`,
          setup(props: any) {
            const a = () => {
              editHandler(props.params.data)
            }
            return {
              a,
            }
          },
        }
      }
      if (o.slotName === 'act1') {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['lockPosition'] = 'right'
        obj['width'] = 105
        obj['cellRenderer'] = {
          template: `<el-button style="color:#165dff;" link @click="a">默认值</el-button>`,
          setup(props: any) {
            const a = () => {
              editHandler1(props.params.data)
            }
            return {
              a,
            }
          },
        }
      }

      return obj
    })
    // 表格准备事件
    const gridOption1 = ref()
    let dataList1 = ref([])
    const gridReady1 = (params: any) => {
      gridOption1.value = params.api
    }
    const defaultColDef1 = {
      sortable: true,
      resizable: true,
      filter: true,
      // flex: 1
    }
    const checkboxChange = (event: Event) => {
      console.log(event)
    }
    let cellChangeBox = {
      template: `
          <el-checkbox v-model="params.data.defaultx"  size="large"  @change="checkboxChange" />`,
      setup(props: any) {
        const checkboxChange = () => {
          //   console.log(props)
          // api.refreshCells()
          props.params.refreshCell()
        }
        return {
          checkboxChange,
        }
      },
    }
    let dc: any[] = tableColumns1.map((o) => {
      let obj = {
        headerName: o.title,
        field: o.key,
        pinned: o['fixed'],
      }
      if (o.slotName === 'act4') {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        // obj['width'] = 300
        obj['lockPosition'] = 'right'
        obj['width'] = 80
        obj['cellRenderer'] = {
          template: `
                    <el-button style="color:#165dff;" link @click="b">修改</el-button>`,
          setup(props: any) {
            const b = () => {
              editHandler2(props.params.data)
            }
            return {
              b,
            }
          },
        }
      }

      if (o.slotName === 'act3') {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['width'] = 90
        // obj['width'] = 250
        obj['lockPosition'] = 'right'
        // obj['cellRenderer'] = {
        //   template: `<a-space>
        //             <a-checkbox @click="b" :default-checked="checkeded"></a-checkbox></a-space>`,
        //   setup(props: any) {
        //     const b = () => {
        //       console.log(props.params.data)
        //       // editHandler3(props.params.data)
        //     }
        //     return {
        //       b,
        //     }
        //   },
        // }
        obj['cellRenderer'] = checkBoxRender
        obj['cellRendererParams'] = {
          color: (data: any) => {
            checkFunction(data)
          },
        }
      }
      return obj
    })
    let checkFunction = (data: any) => {
      dataList1.value.map((item: any) => {
        if (item.id != data.id) {
          item.defaultx = 0
        }
      })
      console.log(data)
      post({
        url: 'pdm/RequireClassifySon/updateDefaultx',
        data: [
          {
            id: data.id,
            requireClassifyID: data.requireClassifyID,
            defaultx: data.defaultx,
          },
        ],
      }).then(({ data, code }: any) => {
        if (code === 200) {
          doRefresh1()
        } else {
          Message.error({
            content: "查询失败！",
            duration: 5000,
          });
        }
      });

    }
    let a = [
      {
        showRowGroup: 'hide_def',
        headerName: '',
        checkboxSelection: true,
        headerCheckboxSelection: true,
        pinned: 'left',
        width: 50,
        resizable: false,
        filter: false,
        sortable: false,
        minWidth: 50,
        maxWidth: 50,
        lockPosition: 'left',
      },
    ]
    tc = a.concat(tc)
    dc = a.concat(dc)
    const total = ref(10)
    const page = ref(1)
    const size = ref(10)
    function PageSize(val: any) {
      pagination.page = val
      doRefresh()
    }
    function change1(val: any) {
      pagination.pageSize = val
      doRefresh()
    }
    // 子表关闭
    const sideNo1 = () => {
      pageData2.showAdd = false
      doRefresh()
    }
    const checkeded = ref<boolean>()
    const localeText1: any = ref(localeText)
    const huiche = () => {
      doRefresh()
    }


    //下拉框得到焦点
    const focusSel1 = () => {
      selCxAll1({ requireClassify: "" });
    }
    //下拉数据
    const options1 = ref<any>(pageData.nameList);
    const loading1 = ref(false);
    const handleSearch1 = (value: any) => {
      if (value) {
        const ob = {
          requireClassify: value,
          deleteState: 0
        }
        loading1.value = true;
        selCxAll1(ob);
        options1.value = pageData.nameList;
        loading1.value = false;
      } else {
        options1.value = []
      }
    };
    //下拉框查询 
    function selCxAll1(val: any) {
      post({
        url: "/pdm/ClientrequireClassify/getFieldValue",
        data: val
      }).then(({ data, code }: any) => {
        if (code === 200) {
          pageData.nameList = data;
        } else {
          Message.error({
            content: "查询失败！",
            duration: 5000,
          });
        }
      });
    }
    const pagingList1: any = ref(pagingList)
    return {
      pagingList1,
      focusSel1,
      handleSearch1,
      huiche,
      localeText1,
      checkeded,
      gridReady1,
      defaultColDef1,
      dc,
      tableColumns1,
      sideNo1,
      PageSize,
      change1,
      total,
      tc,
      defaultColDef,
      gridReady,
      scroll,
      scrollbar,
      tablediv,
      downloadHandler,
      importHandler,
      hasChiese,
      deleteHandler,
      checkFunction,
      sideOk,
      sideOk1,
      formRef,
      dataForm,
      addHandler,
      addHandler1,
      selectedRowKeys,
      pagination,
      tableColumns,
      dataList1,
      table,
      rowKey,
      pageData,
      queryData,
      editHandler,
      editHandler2,
      editHandler3,
      selectHandler,
      options,
      loading,
      handleSearch,
      exports,
      focusSel,
      headerShow,
      pageData2,
      deleteHandler1,
      doRefresh1,
      checkboxChange,
    }
  },
  components: { Toolbar, PageTabelLayout, checkBoxRender },
}
</script>
<style scoped lang="less">
:deep(.ag-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
  user-select: initial;
  -moz-user-select: text;
  -ms-user-select: text;
  -webkit-user-select: text;
}
</style>
